package page;

import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class CustomJFrame extends JFrame {
	JTextField 项目名称;
	JTextField model名称;
	JTextField 模块名称;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public CustomJFrame() {
		this.setTitle("生成代码");
		this.setSize(650, 600);
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		int x = (int) (toolkit.getScreenSize().getWidth() - this.getWidth()) / 2;
		this.setLocation(x, 300);
		this.setResizable(false);
		JPanel panel = new JPanel();
		this.add(panel);
		项目名称 = addLabel(panel, "项目名称", 1, "misalen-web");
		model名称 = addLabel(panel, "model名称", 2, null);
		模块名称 = addLabel(panel, "模块名称", 3, null);
		addCheckBox(panel, 4, "Controller", "Repository", "View-List", "View-Add", "View-Update", "View-Details");
		addButton(panel);
	}

	public void show1() {
		this.setVisible(true);
	}

	private JTextField addLabel(JPanel panel, String name, int line, String text) {
		panel.setLayout(null);
		JLabel userLabel = new JLabel(name);
		userLabel.setBounds(50, 35 * line, 100, 30);
		userLabel.setFont(new Font("Dialog", 1, 18));
		panel.add(userLabel);
		JTextField userText = new JTextField(20);
		userText.setFont(new Font("Dialog", 1, 18));
		userText.setBounds(160, 35 * line, 200, 30);
		userText.setText(text);
		panel.add(userText);
		return userText;
	}

	private void addCheckBox(JPanel panel, int line, String... name) {
		panel.setLayout(null);
		JLabel userLabel = new JLabel("选择");
		userLabel.setBounds(50, 35 * line, 100, 30);
		userLabel.setFont(new Font("Dialog", 1, 18));
		panel.add(userLabel);
		JPanel panel2 = new JPanel();
		panel2.setBounds(160, 35 * line, 400, 100);
		panel.add(panel2);
		panel2.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 3));

		for (int i = 0; i < name.length; i++) {
			JCheckBox checkBox = new JCheckBox(name[i], true);
			checkBox.setFont(new Font("Dialog", 1, 18));
			panel2.add(checkBox);
		}
	}

	private void addButton(JPanel panel) {
		JButton button = new JButton("确定生成");
		button.setBounds(160, 250, 110, 30);
		button.setFont(new Font("Dialog", 1, 18));
		button.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if (模块名称.getText().equals("")) {
					System.err.println(1);
				}
			}
		});
		panel.add(button);
	}

}
